﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _2017._02._28.Stack_generic
{
    class Stack<T>: IEnumerable where T: class
    {
        private T value;
        private T[] kucha;
        public int Count { get; private set; }

        public Stack(int elements)
        {
            kucha = new T[elements];
            Count = 0;
        }

        public T Pop()
        {
            value = kucha[Count];
            Count--;
            return value;
        }

        public void Clear()
        {
         
        }

        public void Push(T value)
        {
            if (Count == kucha.Length)
            {
                Count = 0;
            }
            if (Count == 0)
                kucha[Count] = value;
            else
            {
                kucha[Count + 1] = kucha[Count];
                kucha[Count++] = value;
            }
            
        }

        public IEnumerator GetEnumerator()
        {
            return kucha.GetEnumerator();
        }
    }
}
